package com.company.cloud.club.modules.db.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.company.cloud.club.modules.db.domain.Collection;
import com.company.cloud.club.modules.vo.PersonVo;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * *****************************************************************************
 * <p>
 * 功能名           ：com.qxzychina.vms.mapper
 * 系统名           ：
 * <p>
 * *****************************************************************************
 * Modification History
 * <p>
 * Date        Name                    Reason for Change
 * ----------  ----------------------  -----------------------------------------
 * 2020/7/18     zhangxu                 Created
 */
public interface CollectionMapper extends BaseMapper<Collection> {

    @Select("SELECT * FROM club_collection WHERE type = #{type, jdbcType=VARCHAR} " +
            "AND user_id = #{userId, jdbcType=INTEGER} ORDER BY time_created DESC")
    List<Collection> selectCollectionList(@Param("userId") Integer userId,
                                             @Param("type") String type);

    @Select("SELECT * FROM club_collection WHERE type = #{type, jdbcType=VARCHAR} " +
            "AND res_id = #{resId, jdbcType=VARCHAR} " +
            "AND user_id = #{userId, jdbcType=INTEGER} " +
            "ORDER BY time_created DESC LIMIT 0, 1")
    Collection selectByResId(@Param("type") String type,
                                    @Param("resId") String resId,
                                     @Param("userId") Integer userId);

    @Delete("DELETE FROM club_collection WHERE id = #{id, jdbcType=VARCHAR}")
    boolean deleteByResId(@Param("id") String id);

    @Select("SELECT count(*) FROM club_collection WHERE type = #{type, jdbcType=VARCHAR} " +
            "AND res_id = #{resId, jdbcType=VARCHAR}")
    Integer countNum(@Param("type") String type,
                     @Param("resId") String resId);

    @Select("SELECT * FROM club_collection WHERE res_id = #{resId, jdbcType=VARCHAR} " +
            "AND user_id = #{userId, jdbcType=INTEGER}")
    Collection isColled(@Param("resId") String resId,
                        @Param("userId") Integer userId);

    @Select("SELECT count(*) FROM club_collection WHERE type = 'user' " +
            "AND user_id = #{userId, jdbcType=INTEGER}")
    Integer countRecomNum(@Param("userId") Integer userId);

    @Select("SELECT artist_no as nickname from art_artist_info where user_id=#{userId, jdbcType=INTEGER}")
    PersonVo artistInfoName(@Param("userId") Integer userId);

    @Select("SELECT count(*) FROM `art_v2`.`base_user_follow_info` WHERE `user_id` = #{userId, jdbcType=INTEGER} AND `obj_type` = '80' ")
    Integer followInfoNum(@Param("userId") Integer userId);//关注

    @Select("SELECT count(*) FROM `art_v2`.`base_user_follow_info` WHERE `obj_no` =  #{objNo, jdbcType=VARCHAR} AND `obj_type` = '80'")
    Integer followInfoFsNum(@Param("objNo") String objNo);//粉丝

}
